package com.example.zhihu.fragments;


import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.zhihu.R;
import com.example.zhihu.adapter.RlvDailyNewsAdapter;
import com.example.zhihu.base.BaseFragment;
import com.example.zhihu.bean.DailyNewsBean;
import com.example.zhihu.presenter.DailyPresenter;
import com.example.zhihu.view.DailyNewsView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * A simple {@link Fragment} subclass.
 */
public class DailyNewsFragment extends BaseFragment<DailyPresenter> implements DailyNewsView {
    @BindView(R.id.daily_re)
    RecyclerView daily_re;
    private RlvDailyNewsAdapter adapter;
    private ArrayList<DailyNewsBean.TopStoriesBean> bannerList;
    private ArrayList<DailyNewsBean.StoriesBean> newsList;

    @Override
    protected void initListener() {

    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initView() {
        daily_re.setLayoutManager(new LinearLayoutManager(getContext()));
        bannerList = new ArrayList<>();
        newsList = new ArrayList<>();
        adapter = new RlvDailyNewsAdapter(getContext(), bannerList, newsList);
        daily_re.setAdapter(adapter);
    }

    @Override
    protected void initPresenter() {
        mPresenter=new DailyPresenter();
        mPresenter.getdaily();
    }

    @Override
    protected int getLayout() {
        return R.layout.fragment_daily_news;
    }

    @Override
    public void onSuccess(DailyNewsBean data) {
        List<DailyNewsBean.TopStoriesBean> top_stories = data.getTop_stories();
        List<DailyNewsBean.StoriesBean> stories = data.getStories();
        bannerList.addAll(top_stories);
        newsList.addAll(stories);
        adapter.notifyDataSetChanged();
    }

    @Override
    public void onFail(String error) {

    }

    @Override
    public void showToast(String str) {

    }
}
